fix(auth): clear stale WebView2 cookies before GamePass re-login (#296)#297
Merged
Merged
Conversation
WebView2 keeps a single cookie store per user-data-folder, shared by every window for the lifetime of the host process. After a GamePass logout the server-side session is invalidated but its bfWebToken / ASP.NET_SessionId cookies linger in that store, so the next GamePass login (a new window, same process) inherits the stale token, the portal short-circuits the OAuth round-trip, and the harvest lifts the dead session — surfacing wrong/empty account data. Only restarting the .exe recovered, because that ends the WebView2 browser session. Clear the WebView2 cookie store before seeding the fresh session cookies so every attempt starts from a clean, process-restart- equivalent state. The clear and seed run as two separate native COM passes with a flush gap between them: DeleteAllCookies and AddOrUpdateCookie are both fire-and-return calls with no documented ordering guarantee, so fusing them into one pass risks the pending delete wiping the freshly-seeded cookies. Add a per-page-load diagnostic that logs the WebView's cookie names (never values) so the clear can be verified on a live run.
lshw54
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #296 — after a GamePass login, logging out and logging in again (GamePass) would load the wrong / empty account data, and only fully closing and reopening
Beanfun.exerecovered.Root cause
WebView2 keeps a single cookie store per user-data-folder, shared by every window for the lifetime of the host process. Session cookies (
bfWebToken,ASP.NET_SessionId) have noExpires, so their lifetime is tied to the WebView2 browser session = the whole process.AppState+ the reqwest cookie jar and invalidate the server-side session, but the WebView2 cookie store is never touched.bfWebToken, short-circuits the OAuth round-trip, and the harvest lifts the invalidated session..exeends the WebView2 browser session, which is why it was the only recovery.(The previous #287 only invalidated the prefetched account cache on game switch, which is unrelated to this WebView2 cookie persistence.)
Fix
Clear the WebView2 cookie store before seeding the fresh session cookies in
open_gamepass_window, so every attempt starts from a clean, process-restart-equivalent state.clear_all_cookies_native(DeleteAllCookies).DeleteAllCookiesandAddOrUpdateCookieare both fire-and-return COM calls with no documented ordering guarantee, so fusing them into one pass risked the pending delete wiping the freshly-seeded cookies (which would reproduce the D5 "No such auth key and secret code" failure).set_cookieseed (the quirk is WebView2-specific and the app ships Windows-only).trace_webview_cookies) that logs the WebView's cookie names (never values) so the clear can be verified on a live run.Test plan
cargo build(non-cached recompile),cargo clippy— no warningscargo test --lib gamepass— 22 passedstep=GamepassPageLoad.WebViewCookieslogs — the second login's entry page should show only freshly-seeded session cookies, no stalebfWebToken